package com.yyfax.pay.third.model.to.fuioudeposit;

import java.io.StringWriter;
import java.util.List;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.io.xml.QNameMap;
import com.thoughtworks.xstream.io.xml.StaxDriver;
import com.thoughtworks.xstream.io.xml.StaxWriter;
import com.yyfax.framework.model.BasePO;
import com.yyfax.pay.third.model.to.fuiou.ProtocolPlaceOrderRetryFuiouContent;

/**
 * 余额查询结果响应xml实体
 * 
 * @author heizq
 * @date 2017-09-02 16:35:20
 * @since v2.0.0
 */
@SuppressWarnings("serial")
@XStreamAlias("ap")
public class BalanceQueryResultXMLRsp extends BasePO {

	private BalancePlain plain;

	@XStreamAlias("signature")
	private String sign;

	public BalancePlain getPlain() {
		return plain;
	}

	public void setPlain(BalancePlain plain) {
		this.plain = plain;
	}

	public String getSign() {
		return sign;
	}

	public void setSign(String sign) {
		this.sign = sign;
	}

	/**
	 * XML字符串转换成实体{@link ProtocolPlaceOrderRetryFuiouContent}
	 * 
	 * @author heizq
	 * @date 2017-4-12 10:53:28
	 * @since v1.0.0
	 * @param xml
	 * @return 返回{@link ProtocolPlaceOrderRetryFuiouContent}
	 */
	public static BalanceQueryResultXMLRsp fromXml(String xml) {
		QNameMap qmap = new QNameMap();
		// qmap.setDefaultNamespace("http://www.99bill.com/mas_cnp_merchant_interface");
		qmap.setDefaultPrefix("");
		StaxDriver staxDriver = new StaxDriver(qmap);
		XStream xstream = new XStream(staxDriver);
		xstream.autodetectAnnotations(true);
		xstream.ignoreUnknownElements();
		xstream.alias("ap", BalanceQueryResultXMLRsp.class);
		return (BalanceQueryResultXMLRsp) xstream.fromXML(xml);
	}

	@XStreamAlias("plain")
	public class BalancePlain {
		@XStreamAlias("resp_code")
		private String respCode;

		@XStreamAlias("mchnt_cd")
		private String merchantId;

		@XStreamAlias("mchnt_txn_ssn")
		private String serailNo;

		@XStreamAlias("results")
		private List<BalanceQueryRst> results;

		public String getRespCode() {
			return respCode;
		}

		public void setRespCode(String respCode) {
			this.respCode = respCode;
		}

		public String getMerchantId() {
			return merchantId;
		}

		public void setMerchantId(String merchantId) {
			this.merchantId = merchantId;
		}

		public String getSerailNo() {
			return serailNo;
		}

		public void setSerailNo(String serailNo) {
			this.serailNo = serailNo;
		}

		public List<BalanceQueryRst> getResults() {
			return results;
		}

		public void setResults(List<BalanceQueryRst> results) {
			this.results = results;
		}

		public String toXml() {
			QNameMap qmap = new QNameMap();
			qmap.setDefaultPrefix("");
			StaxDriver staxDriver = new StaxDriver(qmap);
			XStream xstream = new XStream(staxDriver);
			xstream.autodetectAnnotations(true);
			xstream.ignoreUnknownElements();
			xstream.alias("plain", BalanceQueryRst.class);
			try {
				StringWriter strWriter = new StringWriter();
				StaxWriter sw = new StaxWriter(staxDriver.getQnameMap(), staxDriver.getOutputFactory().createXMLStreamWriter(strWriter), false, true);
				xstream.marshal(this, sw);
				sw.close();
				return strWriter.toString().replace("__", "_");
			} catch (Exception e) {
				e.printStackTrace();
			}
			return null;
		}
	}

	@XStreamAlias("result")
	public class BalanceQueryRst {
		/** 用户名 */
		@XStreamAlias("user_id")
		private String accountNo;
		/** 账面总余额 */
		@XStreamAlias("ct_balance")
		private String balance;
		/** 可用余额 */
		@XStreamAlias("ca_balance")
		private String availBalance;
		/** 冻结余额 */
		@XStreamAlias("cf_balance")
		private String frozenAmount;
		/** 未转结余额 */
		@XStreamAlias("cu_balance")
		private String onWayAmount;

		public String getAccountNo() {
			return accountNo;
		}

		public void setAccountNo(String accountNo) {
			this.accountNo = accountNo;
		}

		public String getBalance() {
			return balance;
		}

		public void setBalance(String balance) {
			this.balance = balance;
		}

		public String getAvailBalance() {
			return availBalance;
		}

		public void setAvailBalance(String availBalance) {
			this.availBalance = availBalance;
		}

		public String getFrozenAmount() {
			return frozenAmount;
		}

		public void setFrozenAmount(String frozenAmount) {
			this.frozenAmount = frozenAmount;
		}

		public String getOnWayAmount() {
			return onWayAmount;
		}

		public void setOnWayAmount(String onWayAmount) {
			this.onWayAmount = onWayAmount;
		}
	}
}
